package TrabalhoEda;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class BubbleSort {
	
	@SuppressWarnings("unused")
	private static final String String = null;
	private static final String fname = ("D:\\EDA13_14\\filesave.txt");

	@SuppressWarnings("unused")
	public static  void main(String[] args)
	{		
		
		try 
		{	
			File file = new File(fname);
			FileWriter fw = new FileWriter(file.getAbsoluteFile());
			BufferedWriter fout = new BufferedWriter(fw);
			
			long startTime = System.nanoTime();

			int vetor[] = {4,3,4,5,1,5,6,7,9};
			int aux;
			boolean controla;

			for(int i = 0; i < vetor.length; i++)

			{
				controla = true;
				for(int j= 0; j<(vetor.length -1); j++)
				{
					if(vetor[j] > vetor[j+1])
					{
						aux = vetor[j];
						vetor[j]= vetor[j+1];
						vetor[j+1]= aux;
						controla = false;
					}
				}
				if(controla)
				{
					break;
				}
			}	

			for(int x: vetor){
				String s = Integer.toString(x);
				fout.write(s);
				fout.write("\n");
			}
			for(int y: vetor){
				String s = Integer.toString(y);
				fout.write(s);
				fout.write("\n");
			}
			long duration = System.nanoTime()- startTime;
			System.out.println(Arrays.toString(vetor));
			System.out.println(duration /1.0e9);	
			 
			fout.close();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
		finally
		{
			
		}

		
	
	}
	
	public static void writeLog(String filaname, String vetor) throws IOException
	   {
	      BufferedWriter out = null;
	      try 
	      {	    	  
			out = new BufferedWriter(new FileWriter(fname, true));
	        out.write(vetor + "\n");
	      } 
	      catch (IOException e) 
	      {
	         throw e;
	      }
	      finally
	      {
	         out.close();
	      }
	   }
	   

}
